import time

import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

executable_path = r"E:\Program Files\edgedriver\msedgedriver.exe"
service = EdgeService(executable_path)
options = webdriver.EdgeOptions()
driver = webdriver.Edge(service=service, options=options)
url = r"https://web3.isolarcloud.com.cn/#/login"
driver.get(url)
with open("login.html", 'w', encoding='utf-8') as file:
    file.write(driver.page_source)
username = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable(
        (By.XPATH, r"//input[@class='el-input__inner' and @type='text' and @placeholder='账号']"))
)
password = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable(
        (By.XPATH, r"//input[@class='el-input__inner' and @type='password' and @placeholder='密码']")
    )
)
privacy = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable(
        (By.XPATH, r"//span[@class='agree-privacy-text' and contains(text(), '我已阅读并同意')]")
    )
)
remember = driver.find_element(By.XPATH, "//span[@class='el-checkbox__label' and text()='记住我']")
login = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable(
        (By.XPATH, r"//button[@class='el-button']//span[text()='登录']/..")
    )
)
username.clear()
username.send_keys("15180036081")
password.clear()
password.send_keys("Cyf15070123978")
# privacy.click()
# login.click()
driver.execute_script("arguments[0].click();", privacy)
driver.execute_script("arguments[0].click();", remember)
driver.execute_script("arguments[0].click();", login)
cookies = driver.get_cookies()
session = requests.Session()
